#pragma once

#include <set>

#include "hawking/indexlib/indexlib_service.pb.h"
#include "segment/segment.h"
#include "index/inverted_index/inverted_disk_indexer/inverted_disk_indexer.h"
#include "index/attribute_index/attribute_disk_indexer/single_value_attribute_disk_indexer.h"
#include "index/attribute_index/attribute_disk_indexer/multi_value_attribute_disk_indexer.h"
#include "index/deletion_index/deletion_index_indexer.h"
#include "index/primary_key_index/primary_key_disk_indexer.h"

namespace hawking {
namespace indexlib {

class DiskSegment : public Segment {
public:
    DiskSegment() : Segment() {}
    ~DiskSegment() = default;
    
    bool Load(
        const std::string segment_dir,
        FSFileType data_filetype,
        bool need_increase);

    virtual bool ShouldDump() const override;

    void ExcludeTombPks(const HashSet<uint64_t>& tomb_stone_pks);

    const std::string& SegmentDir() const {
        return segment_dir_;
    }

    FSFileType FileType() const {
        return data_filetype_;
    }

    virtual bool Dump(const std::string& segment_dir) override;

private:
    bool LoadMeta_(const std::string& segment_dir);
    // attribute support increase update but invert could not. TODO
    bool LoadInvertedIndex_(const std::string& segment_dir, FSFileType data_filetype);
    bool LoadAttributeIndex_(
        const std::string& segment_dir, FSFileType data_filetype, bool need_increase);
    bool LoadPkIndex_(const std::string& segment_dir);
    bool InitDeletionIndex_();

private:
    std::string segment_dir_ = "";
    FSFileType data_filetype_ = FSFileType::FSFT_UNKNOWN;
};

}
}